import type { Bean } from '../interface';

export function createFormExport(url: string, submitData: Bean) {
  // 创建Form
  const submitForm = document.createElement('form');
  submitForm.action = url;
  submitForm.method = 'get';
  submitForm.target = '_blank';
  document.body.appendChild(submitForm);

  Object.keys(submitData).forEach((item) => {
    const input: HTMLInputElement = document.createElement('input');
    input.type = 'hidden';
    input.name = item;
    input.value = submitData[item];
    submitForm.appendChild(input);
  });

  submitForm.submit();
  document.body.removeChild(submitForm);
}

export const asyncDelay = (timer: number) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, timer);
  });
};
